package defpackage; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.NetworkInfo; import cn.wps.moffice.OfficeApp; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; import defpackage.jzx; import defpackage.lwd; import java.io.File; import java.io.IOException; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.json.JSONObject; /* renamed from: kae reason: default package */ public final class kae { private static final int[] iPK = {500, 1000, 2000, 5000, 5000, 5000}; private BroadcastReceiver lME; public List<c> lMF = new ArrayList(); private Context mContext; private Gson mGson; /* renamed from: kae$a */ public static class a { public boolean lMo; public String path; public a(String str, boolean z) { this.path = str; this.lMo = z; } } /* renamed from: kae$b */ static class b implements JsonSerializer<JSONObject> { private b() { } /* synthetic */ b(byte b) { this(); } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.reflect.Type, com.google.gson.JsonSerializationContext] */ @Override // com.google.gson.JsonSerializer public final /* synthetic */ JsonElement serialize(JSONObject jSONObject, Type type, JsonSerializationContext jsonSerializationContext) { return new JsonParser().parse(jSONObject.toString()); } } /* renamed from: kae$c */ public interface c { void onConnected(); } /* renamed from: kae$d */ public static class d { public HashMap<String, String> dyQ; String isW; boolean isX; public String url; public final d FG(String str) { this.isX = true; this.isW = str; return this; } } public kae(Context context) { this.mContext = context; GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(JSONObject.class, new b((byte) 0)); this.mGson = gsonBuilder.create(); IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); this.lME = new BroadcastReceiver() { /* class defpackage.kae.AnonymousClass1 */ public final void onReceive(Context context, Intent intent) { if (intent.getBooleanExtra("noConnectivity", false)) { kae.a(kae.this, false); return; } NetworkInfo networkInfo = (NetworkInfo) intent.getExtras().get("networkInfo"); if (networkInfo != null) { kae.a(kae.this, networkInfo.isConnected()); } } }; this.mContext.registerReceiver(this.lME, intentFilter); } private static jyd FE(String str) { return (jyd) new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(str, new TypeToken<jyd>() { /* class defpackage.kae.AnonymousClass2 */ }.getType()); } public static jyd M(int i, String str) { HashMap hashMap = new HashMap(); hashMap.put("X-Requested-With", "XMLHttpRequest"); try { return FE(lwd.f(String.format("https://docer.wps.cn/v3.php/api/android/mb/v3?mb_app=%d&id=%s", Integer.valueOf(i), str), hashMap)); } catch (IOException e) { e.toString(); return null; } } public static String a(d dVar) { try { return dVar.isX ? lwd.c(dVar.url, dVar.isW, dVar.dyQ) : lwd.f(dVar.url, dVar.dyQ); } catch (Exception e) { return null; } } static /* synthetic */ void a(kae kae, String str, int i) { String json = kae.mGson.toJson(new kau(str, i)); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/record/download"; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("postUse wpsSid: ").append(str).append(" mdId: ").append(i); a(FG); } static /* synthetic */ void a(kae kae, boolean z) { for (c cVar : kae.lMF) { if (z) { cVar.onConnected(); } } } public static HashMap<String, String> bWt() { HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("Content-Type", "application/json; charset=utf-8"); return hashMap; } public static jyd dag() { HashMap hashMap = new HashMap(1); hashMap.put("X-Requested-With", "XMLHttpRequest"); try { return FE(lwd.f("https://docer.wps.cn/v3.php/api/android/mb/v3?mb_app=3", hashMap)); } catch (Exception e) { e.printStackTrace(); return null; } } public final kaw FD(String str) { try { kax kax = new kax(); kax.tid = Integer.parseInt(str); new StringBuilder("fetchTemplateDetail tid: ").append(str); return a(kax); } catch (Throwable th) { th.printStackTrace(); return null; } } public final kav FF(String str) { d dVar = new d(); dVar.url = "http://biz.wps.cn/api/docer/ai/recognization/items"; d FG = dVar.FG(str); FG.dyQ = bWt(); String a2 = a(FG); if (a2 != null) { try { return (kav) this.mGson.fromJson(a2, kav.class); } catch (Exception e) { } } return null; } public final a a(String str, String str2, String str3, lwd.a aVar, jzx jzx) { File file = new File(OfficeApp.arx().arM().lZV); if (!file.exists() && !file.mkdirs()) { return null; } File file2 = new File(file, str2); if (file2.exists()) { if (str3.equalsIgnoreCase(kaa.au(file2))) { return new a(file2.getAbsolutePath(), true); } file2.delete(); } File file3 = new File(file, str2 + ".temp"); final lwd.c cVar = new lwd.c(aVar); jzx.a(new jzx.a() { /* class defpackage.kae.AnonymousClass3 */ @Override // defpackage.jzx.a public final void onCancel() { cVar.cPS = true; } }); if (cVar.aa(str, file3.getAbsolutePath())) { if (!file3.exists() || !file3.renameTo(file2) || !str3.equalsIgnoreCase(kaa.au(file2))) { return null; } return new a(file2.getAbsolutePath(), false); } else if (!file3.exists()) { return null; } else { file3.delete(); return null; } } public final kai a(String str, boolean z, int[] iArr, String str2) { kaj kaj = new kaj(); kaj.lMl = z; kaj.lMN = iArr; kaj.lMm = str2; String json = this.mGson.toJson(kaj); d dVar = new d(); dVar.url = str; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("fetchFileUrls isTry: ").append(z).append(" ids: ").append(iArr[0]); String a2 = a(FG); if (a2 != null) { try { return (kai) this.mGson.fromJson(a2, kai.class); } catch (Exception e) { } } return null; } public final kai a(boolean z, int[] iArr, String str) { return a("https://easy.wps.cn/wppv3/fetch/fileurls", z, iArr, str); } public final kan a(kao kao) { String json = this.mGson.toJson(kao); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/match/slide"; d FG = dVar.FG(json); FG.dyQ = bWt(); String a2 = a(FG); if (a2 != null) { try { return (kan) this.mGson.fromJson(a2, kan.class); } catch (Exception e) { } } return null; } public final kap a(kaq kaq) { String json = this.mGson.toJson(kaq); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/match/tmpl"; d FG = dVar.FG(json); FG.dyQ = bWt(); String a2 = a(FG); if (a2 != null) { try { return (kap) this.mGson.fromJson(a2, kap.class); } catch (Exception e) { } } return null; } public final kaw a(kaf kaf) { String json = this.mGson.toJson(kaf); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/fetch/tmpldetail"; d FG = dVar.FG(json); FG.dyQ = bWt(); String a2 = a(FG); if (a2 != null) { try { return (kaw) this.mGson.fromJson(a2, kaw.class); } catch (Exception e) { } } return null; } public final kay au(String str, int i) { String json = this.mGson.toJson(new kaz(str, i)); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/fetch/supporting"; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("fetchTemplateSupporting cat: ").append(str).append(" tdx: ").append(i); String a2 = a(FG); if (a2 != null) { try { return (kay) this.mGson.fromJson(a2, kay.class); } catch (Exception e) { } } return null; } public final Boolean av(String str, int i) { String json = this.mGson.toJson(new kam(str, i)); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/user/isbuymb"; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("checkBought wpsSid: ").append(str).append(" id: ").append(i); String a2 = a(FG); if (a2 != null) { try { return Boolean.valueOf(((kal) this.mGson.fromJson(a2, kal.class)).lMO.lMP == 1); } catch (Exception e) { } } return null; } public final void aw(final String str, final int i) { jcp.ah(new Runnable() { /* class defpackage.kae.AnonymousClass4 */ public final void run() { kae.a(kae.this, str, i); } }); } public final jyj b(int i, String str, int i2) { kah kah = new kah(); kah.lMI = i2; kah.page = i; kah.lGK = str; String json = this.mGson.toJson(kah); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/fetch/tmplbyauthor"; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("fetchAuthorTemplateInfo page: ").append(i).append(" aspectRatio: ").append(str); String a2 = a(FG); if (a2 != null) { try { return (jyj) this.mGson.fromJson(a2, jyj.class); } catch (Exception e) { } } return null; } public final jyl d(int i, String str, String str2, String str3) { kak kak = new kak(); kak.page = i; kak.lGK = str; kak.lGL = str2; kak.title = str3; String json = this.mGson.toJson(kak); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/fetch/preguesslike"; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("fetchGuessYouLikeInfo page: ").append(i).append(" aspectRatio: ").append(str); String a2 = a(FG); if (a2 != null) { try { return (jyl) this.mGson.fromJson(a2, jyl.class); } catch (Exception e) { } } return null; } public final kar d(String str, int i, String str2) { String json = this.mGson.toJson(new kas(str, i, str2)); d dVar = new d(); dVar.url = "https://easy.wps.cn/wppv3/user/cstmowns"; d FG = dVar.FG(json); FG.dyQ = bWt(); new StringBuilder("fetchMyTemplate wpsSid: ").append(str).append(" page: ").append(i).append(" aspectRatio: ").append(str2); String a2 = a(FG); if (a2 != null) { try { return (kar) this.mGson.fromJson(a2, kar.class); } catch (Exception e) { } } return null; } public final void destroy() { try { this.mContext.unregisterReceiver(this.lME); } catch (Throwable th) { } this.mContext = null; this.mGson = null; this.lMF.clear(); this.lMF = null; } }